package summary;

import java.util.PriorityQueue;

/**
 * @Author: 海琳琦
 * @Date: 2022/6/8 20:16
 * https://leetcode.cn/problems/kth-largest-element-in-a-stream/
 */
public class Title703 {

    int k;

    PriorityQueue<Integer> queue;

    public Title703(int k, int[] nums) {
        this.k = k;
        queue = new PriorityQueue<>((a, b)->a.compareTo(b));
        for (int i = 0; i < nums.length; i++) {
            queue.offer(nums[i]);
        }
    }

    public int add(int val) {
        queue.offer(val);
        while (queue.size() > k) {
            queue.poll();
        }
        return queue.peek();
    }

    public static void main(String[] args) {

    }
}
